﻿using System;
using System.Collections.Generic;
using ZyGames.DZPocker.Model;
using ZyGames.Framework.Cache.Generic;
using ZyGames.Framework.Game.Cache;
using ZyGames.Framework.Game.Context;
using ZyGames.Framework.Game.Contract;
using ZyGames.Framework.Game.Contract.Action;
using ZyGames.Framework.Game.Lang;
using ZyGames.Framework.Game.Service;
using System.Linq;
using ZyGames.DZPocker.Bll.Logic;
using ZyGames.DZPocker.Script;
using System.Text.RegularExpressions;
using ZyGames.Framework.Net;
using ZyGames.DZPocker.Tools;

namespace ZyGames.DZPocker.Script.CsScript.Action
{
	/// <summary>
	/// 房主点击成绩单上OK关闭账单
	/// </summary>
	public class Action30078 : BaseAction
	{
		private int tableId;
		private TableData _currentTable;

		public Action30078(HttpGet actionGetter)
			: base((short)ActionType.DZCloseFinalStatementPanel, actionGetter)
		{
		}
		public override bool GetUrlElement()
		{
			if (httpGet.GetInt("TableId", ref tableId))
			{
				return true;
			}
			return false;
		}

		public override bool TakeAction()
		{
			_currentTable = GameRoom.Current.GetTableData(tableId);
			if (_currentTable == null)
			{
				Tool.WriteWarmingLine("消息30078获得房间不存在");
				return false;
			}

			//给所有人广播退出房间
			var param = new Parameters();
			param["TableId"] = tableId;
			GameTable.Current.SyncNotifyAction((int)ActionType.DZForceLeaveTable, _currentTable, param, t =>
			{
				Console.WriteLine("Action 30079 广播玩家强制离开房间");
			});

			GameTable.Current.DeleteTable(_currentTable);
			return true;
		}

		public override void BuildPacket()
		{
			this.PushIntoStack(this.tableId);
		}
	}
}
